package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DistrictCounty;
import com.ruoyi.system.service.IDistrictCountyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区县Controller
 * 
 * @author wfj
 * @date 2025-11-23
 */
@RestController
@RequestMapping("/system/districtCounty")
public class DistrictCountyController extends BaseController
{
    @Autowired
    private IDistrictCountyService districtCountyService;

    /**
     * 查询区县列表
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistrictCounty districtCounty)
    {
        startPage();
        List<DistrictCounty> list = districtCountyService.selectDistrictCountyList(districtCounty);
        return getDataTable(list);
    }

    /**
     * 导出区县列表
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:export')")
    @Log(title = "区县", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistrictCounty districtCounty)
    {
        List<DistrictCounty> list = districtCountyService.selectDistrictCountyList(districtCounty);
        ExcelUtil<DistrictCounty> util = new ExcelUtil<DistrictCounty>(DistrictCounty.class);
        util.exportExcel(response, list, "区县数据");
    }

    /**
     * 获取区县详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(districtCountyService.selectDistrictCountyById(id));
    }

    /**
     * 新增区县
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:add')")
    @Log(title = "区县", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistrictCounty districtCounty)
    {

        return toAjax(districtCountyService.insertDistrictCounty(districtCounty));
    }

    /**
     * 修改区县
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:edit')")
    @Log(title = "区县", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistrictCounty districtCounty)
    {
        return toAjax(districtCountyService.updateDistrictCounty(districtCounty));
    }

    /**
     * 删除区县
     */
    @PreAuthorize("@ss.hasPermi('system:districtCounty:remove')")
    @Log(title = "区县", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(districtCountyService.deleteDistrictCountyByIds(ids));
    }
}
